package 每日一题;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 228. 汇总区间
 */
public class Date0110 {

    /**
     * 题解：排序
     * @param nums
     * @return
     */
    public List<String> summaryRanges(int[] nums) {
        List<String> res = new ArrayList<>();
        if (nums.length ==0){
            return res;
        }
        Arrays.sort(nums);


        for (int i=0;i<nums.length;i++){

            String str = String.valueOf(nums[i]);
            int end =0;//连续子序列的结束索引
            while (i+1<nums.length && nums[i+1] == nums[i]+1){
                end =i+1;
                i++;
            }
            if (end!=0){
                str += "->"+ nums[end];
            }



           // str = "\""+str+"\"";
            res.add(str);
            

        }

        return res;

    }
}
